#ifndef _timberyard_threadpool_h_
#define _timberyard_threadpool_h_

#include <tr1/functional>
#include <list>
#include <boost/thread.hpp>
#include <timberyard/queue.h>
#include <timberyard/utils.h>

namespace Timberyard {

class ThreadPool : private Uncopyable {
	public:
		ThreadPool(unsigned int min=1, unsigned int max=1, unsigned int idle=10);
		void Exec(std::tr1::function<void ()> fn);
	protected:
		unsigned int m_total;
		unsigned int m_min;
		unsigned int m_max;
		unsigned int m_max_idle;
		unsigned int m_idle;
		Queue<std::tr1::function<void ()> > m_queue;
		boost::mutex m_mutex;

		void Tidy(); 
		void Run();
		void AddThread();
		bool TooMany();

};

}


#endif // _timberyard_threadpool_h_
